package vn.vfriends.vbox.util;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import vn.vfriends.vbox.service.RoleService;
import vn.vfriends.vbox.service.UserService;
import vn.vfriends.vbox.service.impl.RoleServiceImpl;
import vn.vfriends.vbox.service.impl.UserServiceImpl;

/**
 *
 * @author tuancn
 */
public class ServiceUtil {
    
    private static final Logger logger = LoggerFactory.getLogger(ServiceUtil.class);
    
    private static UserService userService;
    
    private static RoleService roleService;
    
    static {
        Properties properties = new Properties();
        try {
            InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("api.properties");
            properties.load(inputStream);
            
            String apiUrl = properties.getProperty("API_URL");
            String apiUser = properties.getProperty("API_USER");
            String apiPassword = properties.getProperty("API_PASSWORD");
            
            userService = new UserServiceImpl(apiUrl, apiUser, apiPassword);
            roleService = new RoleServiceImpl(apiUrl, apiUser, apiPassword);
        } catch (IOException e) {
            logger.error(e.getMessage(), e);
        }
    }

    public static UserService getUserService() {
        return userService;
    }

    public static RoleService getRoleService() {
        return roleService;
    }
}
